using System;
using System.Collections.Generic;
using System.Text;
using TrainTicket.DAO;
using System.Data;
using TrainTicket.VO;

namespace TrainTicket.TRAIN
{
    public class CustomerTRAIN
    {
        CustomerDAO _customerDAO;
        public CustomerTRAIN() 
        {
            _customerDAO = new CustomerDAO();
        }
        //Get all Data
        public DataTable GetAllCustomer() 
        {
            return _customerDAO.GetAllCustomer();
        }

        
        //Insert Customer
        public int InsertCustomerOutput(string customerName, int age, string mobile, string email, string address) 
        {
            return _customerDAO.InsertCustomerOutput(customerName, age, mobile, email, address);
        }

        //Insert Customer
        public int InsertCustomer(string customerName, int age, string mobile, string email, string address) 
        {
            return _customerDAO.InsertCustomer(customerName, age, mobile, email, address);
        }
        //Check Customer Name
        public bool CheckCustomerName(string customerName)
        {
            if (_customerDAO.CheckCustomerName(customerName)>0)
            {
                return true;
            }
            else 
            {
                return false;
            }
        }
        //Update Customer
        public int UpdateCustomer(int customerID, string customerName, int age, string mobile, string email, string address) 
        {
            return _customerDAO.UpdateCustomer(customerID, customerName, age, mobile, email, address);
        }
        //Get Customer By ID
        public Customer GetAllCustomerByID(int customerID) 
        {
            DataTable dbTable = _customerDAO.GetAllCustomerByID(customerID);
            Customer customer= new Customer();
            foreach (DataRow dr in dbTable.Rows)
            {
                customer.CustomerID= int.Parse(dr["CustomerID"].ToString());
                customer.CustomerName= dr["CustomerName"].ToString();
                customer.Age = int.Parse(dr["Age"].ToString());
                customer.Mobile = dr["Mobile"].ToString();
                customer.Email= dr["Email"].ToString();
                customer.Address = dr["Address"].ToString();
            }
            return customer;
        }
        //delete customer
        public int DeleteCustomer(int customerID)
        {
            return _customerDAO.DeleteCustomer(customerID);
        }
        # region //Search All
        //Search Customer by CustomerName
        
        //search account by address
        public List<Customer> GetAllCustomerByCustomerName(string customerName)
        {
            List<Customer> list = new List<Customer>();
            DataTable dbTable = _customerDAO.GetDataByCustomerName(customerName);
            foreach (DataRow dr in dbTable.Rows)
            {
                Customer customer= new Customer();
                customer.CustomerID= int.Parse(dr["CustomerID"].ToString());
                customer.CustomerName = dr["CustomerName"].ToString();
                customer.Age = int.Parse(dr["Age"].ToString());
                customer.Mobile = dr["Mobile"].ToString();
                customer.Email= dr["Email"].ToString();
                customer.Address= dr["Address"].ToString();
                list.Add(customer);
            }
            return list;
        }
        //Search Customer by Email
        public DataTable GetAllCustomerByEmail(string email)
        {
            return _customerDAO.GetDataByEmail(email);
        }
        //Search Customer By Address
        public DataTable GetAllCustomerByAddress(string address)
        {
            return _customerDAO.GetCustomerByAddress(address);
        }
       
        #endregion
    }
}
